


function showProgress(progressid){
    var img=new Image();
    img.src=document.getElementById(progressid).src;	
    var width=img.width,height=img.height;
   document.getElementById(progressid+"_progress").style.display="";

	 mui("#"+progressid+"_progress").progressbar({progress:1}).show();
}
function hideProgress(progressid){
    document.getElementById(progressid+"_progress").style.display="none";		 
	 mui("#"+progressid+"_progress").progressbar({progress:1}).hide();
}
function setProgress(progressid, percent){
	//$("#"+progressid+"_progress").html(percent)
	 mui("#"+progressid+"_progress").progressbar().setProgress(percent);
}


function clickbtn(pfs,imgid) {
	var Qiniu = new QiniuJsSDK();
	var uploader = Qiniu.uploader({
        runtimes: 'html5,flash,html4',
        browse_button: pfs,        
        container: 'container',// 上传区域 DOM ID，默认是 browser_button 的父元素，
        dragdrop: true,// 开启可拖曳上传
        drop_element: 'container',
        max_file_size: '20mb',
        flash_swf_url: 'plug-in/plupload/js/Moxie.swf',
        max_retries: 3,// 上传失败最大重试次数
        chunk_size: '4mb', // 分块上传时，每块的体积
        multi_selection: !(mOxie.Env.OS.toLowerCase()==="ios"),
        uptoken_url: $('#uptoken_url').val(),      
        domain: $('#domain').val(),
        // 默认 false，key 为文件名。若开启该选项，JS-SDK 会为每个文件自动生成key（文件名）
        get_new_uptoken: false,
        unique_names: true,
        auto_start: true, // 选择文件后自动上传，若关闭需要自己绑定事件触发上传,
        log_level: 5,     
        init: {
        	PostInit: function() {
        		var obj = document.getElementById('filelist');
        		if (!obj){
        		}else{
        			obj.innerHTML = ''; 
        		}
    		},
            'FilesAdded': function(up, files) {
            	 plupload.each(files, function(file) {
                     // 文件添加进队列后,处理相关的事情
            		 //alert("FilesAdded:"+file);
                     var obj = document.getElementById('filelist');
                     if (!obj){            		 	
            	 	 }else{
            	 		obj.innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b> <img></img></div>';
            	 	 }
                 }); 
            	showProgress(imgid);
            },
            'BeforeUpload': function(up, file) {
            	// 每个文件上传前,处理相关的事情
            	//alert("BeforeUpload:"+file);
            },
            'UploadProgress': function(up, file) {
            	// 每个文件上传时,处理相关的事情
            	//alert("UploadProgress:"+file);
            	var obj = document.getElementById('file.id');
                if (!obj){       				
                }else{
                	obj.getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
                }
              setProgress(imgid,file.percent);
            }, 
            'FileUploaded': function(up, file, info) {
                var obj = document.getElementById(file.id);
                if (!obj){
                }else{
                	 document.getElementById(file.id).getElementsByTagName('img')[0].innerHTML = '<span>' + file.percent + "%</span>";                                                       
          			//or $("#id").attr("src","a.png")   
                }

                var fileInfoObj = jQuery.parseJSON(info);   
                $("#"+imgid).attr('src',  $('#domain').val()+fileInfoObj.key+"-indexthumb");
                $("#"+imgid).attr('alt',  $('#domain').val()+fileInfoObj.key);
                $("#"+imgid+"_hid").val($('#domain').val()+fileInfoObj.key+"-indexthumb");
               
            },
            'UploadComplete': function() {

           hideProgress(imgid);
            },
            'Error': function(up, err, errTip) {

            }

        }
    });
}



